package com.runlooker.runer.queue;

import java.util.LinkedList;

import com.runlooker.runer.entity.PresenceEntity;

/**
 * 
 * 出席信息队列
 * 
 * @author YINENG
 *
 */
public class PresenceQueue {
	private final LinkedList<PresenceEntity> queue = new LinkedList<PresenceEntity>();

	/**
	 * 
	 * 从消息队列中获得出席信息实例
	 * 
	 * @return
	 */
	public synchronized PresenceEntity getPresenceEntity() {
		while (queue.size() <= 0) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return queue.removeFirst();
	}

	/**
	 * 
	 * 将出席信息实例添加到消息队列
	 * 
	 * @param entity
	 */
	public synchronized void putPresenceEntity(PresenceEntity entity) {
		queue.addLast(entity);
		notifyAll();
	}
}
